package com.longder.kindergarten.controller;

import com.longder.kindergarten.entity.dto.Response;
import com.longder.kindergarten.entity.po.ClassDiet;
import com.longder.kindergarten.service.ClassDietManageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 餐饮管理控制器
 */
@Slf4j
@RestController
@RequestMapping("/classDietManage")
public class ClassDietManageController {

    @Resource
    private ClassDietManageService classDietManageService;

    /**
     * 添加或编辑班级饮食
     */
    @PostMapping("/addOrEditDiet")
    public Response addOrEditDiet(@RequestBody ClassDiet classDiet){
        try{
            classDietManageService.addOrEditDiet(classDiet);
            return Response.success("保存成功");
        }catch(Exception e){
            log.error(e.getMessage(),e);
            return Response.error("保存失败："+e.getMessage());
        }
    }

    /**
     * 查询某个饮食内容
     */
    @GetMapping("/getDiet/{dietId}")
    public Response getDiet(@PathVariable("dietId") Long dietId){
        return Response.success(classDietManageService.getDiet(dietId));
    }


    /**
     * 删除班级饮食
     */
    @PostMapping("/removeDiet/{dietId}")
    public Response removeDiet(@PathVariable("dietId") Long dietId){
        return Response.success("删除成功");
    }

    /**
     * 查询某个班级的饮食列表
     */
    @GetMapping("/listByClassId/{classId}")
    public Response listByClassId(@PathVariable("classId") Long classId){
        return Response.success(classDietManageService.listByClassId(classId));
    }



}
